package com.mco.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.time.Duration;

/**
 * @author ：liao.wei
 * @date ：2023/9/18 21:15
 * @package : com.mco.utils
 */
public class RedisUtils {
	private static Logger logger = LoggerFactory.getLogger(RedisUtils.class);
	
	public static final String REDIS_IP_ADDR = "120.77.64.190";
	public static final String REDIS_PWD = "111111";
	
	public static JedisPool jedisPool;
	
	static {
		JedisPoolConfig poolConfig = new JedisPoolConfig();
		poolConfig.setMaxIdle(8);
		poolConfig.setMinIdle(2);
		poolConfig.setMaxWait(Duration.ofSeconds(30000));
		jedisPool = new JedisPool(poolConfig, REDIS_IP_ADDR, 6379, 10000, REDIS_PWD);
	}
	
	public static Jedis getJedis() throws Exception {
		if (null != jedisPool) {
			return jedisPool.getResource();
		}
		throw new Exception("Jedispool is not ok");
	}
}
